package com.lkqandzzy.service.impl;

import com.lkqandzzy.dao.RecordDao;

import com.lkqandzzy.entity.PageInfo;
import com.lkqandzzy.entity.Record;
import com.lkqandzzy.service.RecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("recordService")
@Transactional
public class RecordServiceImpl implements RecordService {

    @Autowired
    private RecordDao recordDao;

    @Override
    public PageInfo<Record> findPageInfo(String customer_name, String theme, Integer pageIndex, Integer pageSize) {
        PageInfo<Record> pi = new PageInfo<Record>();
        pi.setPageIndex(pageIndex);
        pi.setPageSize(pageSize);
        //获取总条数
        Integer totalCount = recordDao.totalCount(customer_name,theme);
        if (totalCount>0){
            pi.setTotalCount(totalCount);
            //每一页显示跟踪记录数
            //currentPage = (pageIndex-1)*pageSize  当前页码数减1*最大条数=开始行数
            List<Record> leavingSchoolList =	recordDao.getRecordList(customer_name,theme,
                    (pi.getPageIndex()-1)*pi.getPageSize(),pi.getPageSize());
            pi.setList(leavingSchoolList);
        }
        return pi;

    }

    @Override
    public int deleteRecord(Integer r_id) {
        return recordDao.deleteRecord(r_id);
    }

    @Override
    public int addRecord(Record record) {
        return recordDao.addRecord(record);
    }

    @Override
    public int updateRecord(Record record) {
        return recordDao.updateRecord(record);
    }

    @Override
    public Record findRecordById(Integer r_id) {
        Record c = recordDao.findRecordById(r_id);
        return  c;
    }

    @Override
    public List<Record> getAll() {
        List<Record> RecordList = recordDao.getAll();
        return  RecordList;
    }
}
